Properties

$html_elements

$html_elements : array

Type

array — Allowed HTML elements (default)

$ignore_elements

$ignore_elements : array

Type

array — Ignore these HTML tags and their content

$html_attribs

$html_attribs : array

Type

array — Allowed HTML attributes

$void_elements

$void_elements : array

Type

array — Elements which could be empty and be returned in short form (<tag />)

$body_attribs

$body_attribs : array

Type

array — Additional allowed attributes of body element

$extlinks

$extlinks : bool

Type

bool — State indicating existence of linked objects in HTML

$config

$config : array

Type

array — Current settings

$handlers

$handlers : array

Type

array — Registered callback functions for tags

$_html_elements

$_html_elements : array

Type

array — Allowed HTML elements

$_ignore_elements

$_ignore_elements : array

Type

array — Ignore these HTML tags but process their content

$_void_elements

$_void_elements : array

Type

array — Elements which could be empty and be returned in short form (<tag />)

$_html_attribs

$_html_attribs : array

Type

array — Allowed HTML attributes

$_css_prefix

$_css_prefix : string

Type

string — A prefix to be added to id/class/for attribute values

$max_nesting_level

$max_nesting_level : int

Type

int — Max nesting level

$max_nesting_level_error

$max_nesting_level_error : bool

Type

bool — Indicates that a nesting level error was logged

$is_xml

$is_xml : bool

Type

bool — True if current document is XML

Methods

__construct()

__construct(array  $p = []) : mixed

Class constructor

Parameters

array $p

Configuration options: allow_remote: is a boolean to allow link to remote resources (images/css) blocked_src: string with image-src to be used for blocked remote images show_washed: is a boolean to include washed out attributes as x-washed cid_map: is an array where cid urls index urls to replace them charset: is a string containing the charset of the HTML document, to be used if the charset is not defined in the document css_prefix: A prefix to be added to id/class/for attribute values html_elements: Additional allowed HTML elements ignore_elements: Additional HTML elements to ignore html_attribs: Additional allowed HTML attributes void_elements: Elements which could be empty and be returned in short form ()

Returns

mixed —

add_callback()

add_callback(string  $tag, callable  $callback) : mixed

Register a callback function for a certain tag

Parameters

string $tag

HTML tag name

callable $callback

Callback function

Returns

mixed —

wash()

wash(string  $html) : string

Main function, give it untrusted HTML, tell it if you allow loading remote images and give it a map to convert "cid:" urls.

Parameters

string $html

HTML content

Returns

string —

Washed HTML content

get_config()

get_config(string  $prop) : mixed

Getter for config parameters

Parameters

string $prop

Configuration parameter name

Returns

mixed —

Configuration parameter value

html_tag_callback()

html_tag_callback(array  $matches) : string

Callback function for HTML tags fixing

Parameters

array $matches

Matched elements (from preg_replace_callback())

Returns

string —

Replacement string

resolve_base()

resolve_base(string  $body) : string

Convert all relative URLs according to a <base> in HTML

Parameters

string $body

HTML body

Returns

string —

HTML body

fix_broken_lists()

fix_broken_lists(string  $html) : mixed

Fix broken nested lists, they are not handled properly by DOMDocument (#1488768)

Parameters

string $html

HTML content

Returns

mixed —

fix_html5()

fix_html5(string  $html) : string

Cleanup and workarounds on input to Masterminds/HTML5

Parameters

string $html

HTML content

Returns

string —

HTML content

explode_style()

explode_style(string  $style) : array

Explode css style value

Parameters

string $style

CSS style

Returns

array —

List of CSS rules

wash_style()

wash_style(string  $style) : string

Check CSS style

Parameters

string $style

CSS style

Returns

string —

Washed CSS style

wash_attribs()

wash_attribs(\DOMNode  $node) : string

Take a node and return allowed attributes and check values

Parameters

\DOMNode $node

Document element

Returns

string —

Washed element attributes

wash_uri()

wash_uri(string  $uri, bool  $blocked_source = false, bool  $is_image = true) : string

Wash URI value

Parameters

string $uri

URI

bool $blocked_source

Block remote source

bool $is_image

URI points to an image

Returns

string —

Washed URI

wash_link()

wash_link(string  $href) : string

Wash Href value

Parameters

string $href

Href attribute value (link)

Returns

string —

Washed href

is_link_attribute()

is_link_attribute(string  $tag, string  $attr) : bool

Check it the tag/attribute may contain an URI

Parameters

string $tag

Element name

string $attr

Attribute name

Returns

bool —

True if attribute may contain an URI, False otherwise

is_image_attribute()

is_image_attribute(string  $tag, string  $attr) : bool

Check it the tag/attribute may contain an image URI

Parameters

string $tag

Element name

string $attr

Attribute name

Returns

bool —

True if attribute may contain an image URI, False otherwise

is_funciri_attribute()

is_funciri_attribute(string  $tag, string  $attr) : bool

Check it the tag/attribute may contain a FUNCIRI value

Parameters

string $tag

Element name

string $attr

Attribute name

Returns

bool —

True if attribute may contain a FUNCIRI value, False otherwise

attribute_value()

attribute_value(\DOMElement  $node, string  $attr_name, string  $attr_value) : bool

Check if a specified element has an attribute with specified value.

Do it in case-insensitive manner.

Parameters

\DOMElement $node

The element

string $attr_name

The attribute name

string $attr_value

The attribute value to find

Returns

bool —

True if the specified attribute exists and has the expected value

dumpHtml()

dumpHtml(\DOMNode  $node, int  $level = 20) : string

The main loop that recurse on a node tree.

It output only allowed tags with allowed attributes and allowed inline styles

Parameters

\DOMNode $node

HTML element

int $level

Recurrence level (safe initial value found empirically)

Returns

string —

HTML content

cleanup()

cleanup(string  $html) : string

Clean HTML input

Parameters

string $html

HTML content

Returns

string —

Clean HTML content